﻿using il.lua;

public class BlockExpression : Expression
{
    private List<Expression> _expressions = new();

    public void Add(Expression exception)
    {
        _expressions.Add(exception);
    }

    public override void Print()
    {
        ConsoleEx.Indent++;
        var count = _expressions.Count - 1;
        for (var i = 0; i < count; i++)
        {
            var expression = _expressions[i];
            expression.Print();
            ConsoleEx.CodeLn();
        }
        if (count >= 0)
        {
            var last = _expressions[count];
            if (last is ReturnExpression ret && ret.Result != null)
            {
                last.Print();
                ConsoleEx.CodeLn();
            }
        }
        ConsoleEx.Indent--;
    }
}